package com.zhw.andfix.net;

import com.zhw.andfix.BuildConfig;

import cn.droidlover.xdroidmvp.net.XApi;


/**
 * ApiService
 * Created by Administrator on 2016/12/31.
 */

public class ApiService {

    private static IApi api;
    private static IAppConfigInfoApi appConfigInfoApi;

    public static IApi getApi() {
        if (api == null) {
            synchronized (ApiService.class) {
                if (api == null) {
                    String baseUrl;
                    if (BuildConfig.DEBUG){
                        baseUrl = BuildConfig.HTTP_BASE_URL_DEBUG;
                    } else {
                        baseUrl = BuildConfig.HTTP_BASE_URL;
                    }
                    api = XApi.getInstance().getRetrofit(baseUrl, true).create(IApi.class);
                }
            }
        }
        return api;
    }

    public static void setApiToNull(){
        if (api != null) {
            api = null;
        }
    }

    public static IAppConfigInfoApi getAppConfigInfoApi() {
        if (appConfigInfoApi == null) {
            synchronized (ApiService.class) {
                if (appConfigInfoApi == null) {
                    appConfigInfoApi = XApi.getInstance().getRetrofit(BuildConfig.APP_CONFIG_INFO_BASE_URL, true).create(IAppConfigInfoApi.class);
                }
            }
        }
        return appConfigInfoApi;
    }
}
